package org.csu.jpetstore_front.controller.front;


import org.csu.jpetstore_front.common.CommonResponse;
import org.csu.jpetstore_front.entity.Category;
import org.csu.jpetstore_front.entity.Item;
import org.csu.jpetstore_front.entity.Product;
import org.csu.jpetstore_front.entity.spartproduct;
import org.csu.jpetstore_front.node.PassToken;
import org.csu.jpetstore_front.service.CatalogService;
import org.csu.jpetstore_front.vo.ItemVO;
import org.csu.jpetstore_front.vo.SproductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/catalog/")
public class CatalogController {
    @Autowired
    private CatalogService catalogService;


    @GetMapping("categories")
    @ResponseBody
    @PassToken
    public CommonResponse<List<Category>> getCategoryList(){
        return catalogService.getCategoryList();
    }

    @GetMapping("categories/{id}")
    @ResponseBody
    @PassToken
    public CommonResponse<Category> getCategory(@PathVariable("id") String categoryId){
        return catalogService.getCategory(categoryId);
    }

    @GetMapping("/{id}/items")
    @ResponseBody
    @PassToken
    public CommonResponse<Item> getItemsByCategoryId(@PathVariable("id") String categoryId) {
        return null;
    }

    @GetMapping("categories/{id}/products")
    @ResponseBody
    @PassToken
    public CommonResponse<Product> getProduct(@PathVariable("id") String productId)
    {
        return catalogService.getProduct(productId);
    }

    @GetMapping("products/{categoryId}")
    @ResponseBody
    @PassToken
    CommonResponse<List<Product>> getProductListByCategory(@PathVariable("categoryId") String categoryId)
    {
        return catalogService.getProductListByCategory(categoryId);
    }

    @GetMapping("products/{id}/items")//id 为productid AV-SB-02
    @ResponseBody
    @PassToken
    public CommonResponse<List<ItemVO>> getItemsByProductId(@PathVariable("id") String productId){
        return catalogService.getItemListByProduct(productId);
    }
    @GetMapping("items/{itemId}")
    @ResponseBody
    @PassToken
    public CommonResponse<ItemVO> getItem(@PathVariable("itemId") String itemId) {
        return catalogService.getItem(itemId);
    }
    @GetMapping("allitems")
    @ResponseBody
    @PassToken
    public CommonResponse<List<ItemVO>> getAllItems(){
        return catalogService.getAllItems();
    }
    @GetMapping("product_item")
    @ResponseBody
    @PassToken
    public CommonResponse<List<SproductVO>> getproduct_item(){
        return catalogService.getproduct_item();
    }
}